#-*- Makefile -*-
include ../../gnuwin32/MkRules

MODULE=lapack
all: 
	@$(MAKE) --no-print-directory -f Makefile.win -s makeMakedeps 
	@$(MAKE) --no-print-directory -f Makefile.win ../../../bin/Rlapack.dll 
ifdef USE_IMPLIBS
	@$(MAKE) --no-print-directory -f Makefile.win implib
endif
	@$(MAKE) --no-print-directory -f Makefile.win ../../../modules/$(MODULE).dll

CSOURCES = Lapack.c
OBJS=$(CSOURCES:.c=.o) dllversion.o
LIBSOURCES = dlamch.f dlapack0.f dlapack1.f dlapack2.f dlapack3.f dlapack4.f cmplx.f
LIBOBJECTS = $(LIBSOURCES:.f=.o) Rlapackrc.o

# will be overridden on call from src/gnuwin32/Makefile
OPTFLAGS=-O3 -Wall -pedantic -std=gnu99
FOPTFLAGS=-O3

CPPFLAGS=-I../../include -DHAVE_CONFIG_H
CFLAGS=$(OPTFLAGS)
FFLAGS=$(FOPTFLAGS)
dlamch-FFLAGS=-ffloat-store

../../../modules/$(MODULE).dll: $(MODULE).dll
	$(MKDIR) -p ../../../modules
	$(CP) $< $@

lapack-DLLLIBS=-L../../../$(IMPDIR) -lRlapack -lRblas -lR

implib: libRlapack.dll.a
	@$(CP) libRlapack.dll.a ../../../lib

libRlapack.dll.a: Rlapack.def

Rlapack.def: $(LIBOBJECTS)
	@$(ECHO) EXPORTS > $@
	@$(NM) $^ | $(SED) -n 's/^.* [BCDRT] _/ /p' | $(SORT) | uniq >> $@


$(MODULE).dll: $(OBJS)

../../../bin/Rlapack.dll: $(LIBOBJECTS)
	$(DLL) -shared -s -o $@ $^ -L../../../$(IMPDIR) -lR -lRblas $(FLIBS)

clean:
	@$(RM) Makedeps *.d *.o $(MODULE).def $(MODULE).dll Rlapack.def \
	  Rlapack.dll *.a


# Dependencies
dllversion.o: ../../include/Rversion.h
Rlapackrc.o: ../../include/Rversion.h

DEPS=$(CSOURCES:.c=.d)

makeMakedeps: $(DEPS)
	@$(RM) Makedeps
	@cat $(DEPS) >> Makedeps

-include Makedeps
